<?php

namespace Biz\service\advertisement\apiModule;


use Biz\model\advertisement\MPositionExtend;
use Doraemon\pockets\constInterface\PopupServiceConf;
use Doraemon\service\Popups\PopupsApi;

class SearchResultPopup extends TabPopups
{

    public function extListMap($ids)
    {
        $popup = empty($ids) ? [] : PopupsApi::getListByRelateIds($ids);
        $extend = empty($ids) ? [] : MPositionExtend::fetchExtListByIds($ids);
        foreach ($extend as $id => &$v) {
            $v['popup'] = $popup[$id] ?? [];
        }
        return $extend;
    }

    public function formatAdmListExtInfo(&$v, $map)
    {
        $v['ext'] = $map[$v['id']] ?? [];
    }

    public function extCheckActive($v, $extInput)
    {
        $keyword = $extInput['keyword'] ?? '';
        $config = $v['ext']['key_word'] ?? '';
        $config = explode(',', $config);
        return strlen($keyword) && in_array($keyword, $config);
    }

    public function getExtInfo($baseInfo)
    {
        $id = $baseInfo['id'] ?? 0;

        $info = empty($id) ? [] : MPositionExtend::fetchInfoById($id);

        $id = $baseInfo['id'] ?? 0;

        //弹窗组件
        $popups = $id > 0 ? PopupsApi::get($id) : [];
        if (!empty($popups) && $popups['type'] == PopupServiceConf::STYLE_LOTTIE) {
            $popups['bgPic_' . PopupServiceConf::STYLE_LOTTIE] = $popups['bgPic'];
            $popups['bgPic'] = '';
        }

        return $info + ['popups' => $popups];
    }

}